-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add slice function #250
Add slice function #250
Conversation
In terms of LOC this is + 15 lines
- 35 lines :D |
Thanks @megawac! Sorry for taking so long. I have a few minor comments. |
|
||
Stream.prototype.take = function (n) { | ||
if (n === 0) { | ||
if (start < 0 || start >= end) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
start < 0
should be treated as start === 0
. Like how drop
handles n < 0
. Otherwise, slice(-1, Infinity)
and drop(-1)
won't the the same.
Also, add a
if (start === 0 && end === Infinity) {
return this;
}
so that we can drop the if (n <= 0)
check in drop
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is Misreaddrop(-1)
supposed to do because this probably breaks it (there are no unit tests for drop or take with negative indices)
*/ | ||
|
||
Stream.prototype.take = function (n) { | ||
var s = this.slice(0, n); | ||
s.id = 'take:' + s.id; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this stuff important?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The s.id
? No. It's mostly for debugging. No harm in leaving it though.
Thanks. This looks good to me. There's some talk of maybe changing the name of this transform to |
We should probably stick with |
Sounds good. |
This pretty much unifies the
drop
andtake
functions while adding a potentially useful function :)